Fix use of function in -replacement-alist
authorJustin Burkett <justin@burkett.cc>
Fri, 25 Nov 2016 14:00:25 +0000 (09:00 -0500)
committerJustin Burkett <justin@burkett.cc>
Fri, 25 Nov 2016 14:00:25 +0000 (09:00 -0500)
Wasn't actually deleting nil results

which-key.el

index b5b671c383365f8a1cd4f59ae1cc3e6ed8367fad..6828f42fe2d0bba93b213eca3cb8698bfc51c1f4 100644 (file)
@@ -1299,6 +1299,7 @@ which are strings. KEY is of the form produced by `key-binding'."
                    key-binding which-key-replacement-alist
                    'which-key--replacement-test))))
     (cond ((null res) key-binding)
+          ((functionp res) (funcall res key-binding))
           ((consp res)
            (cons
             (cond ((and (car res) (car which-key--last-replace-key))
@@ -1312,8 +1313,7 @@ which are strings. KEY is of the form produced by `key-binding'."
                     (cdr which-key--last-replace-key)
                     (cdr res) (cdr key-binding) t))
                   ((cdr res) (cdr res))
-                  (t (cdr key-binding)))))
-          ((functionp res) (funcall res key-binding)))))
+                  (t (cdr key-binding))))))))
 
 (defsubst which-key--current-key-list (&optional key-str)
   (append (listify-key-sequence which-key--current-prefix)
@@ -1446,22 +1446,25 @@ alists. Returns a list (key separator description)."
   (let ((sep-w-face
          (propertize which-key-separator 'face 'which-key-separator-face))
         (local-map (current-local-map)))
-    (mapcar
-     (lambda (key-binding)
-       (let* ((key (car key-binding))
-              (orig-desc (cdr key-binding))
-              (group (which-key--group-p orig-desc))
-              (keys (which-key--current-key-string key))
-              (local (eq (which-key--safe-lookup-key local-map (kbd keys))
-                         (intern orig-desc)))
-              (hl-face (which-key--highlight-face orig-desc))
-              (key-binding (which-key--maybe-replace (cons keys orig-desc))))
-         (list (which-key--propertize-key
-                (car (last (split-string (car key-binding) " "))))
-               sep-w-face
-               (which-key--propertize-description
-                (cdr key-binding) group local hl-face orig-desc))))
-     unformatted)))
+    (delq
+     nil
+     (mapcar
+      (lambda (key-binding)
+        (let* ((key (car key-binding))
+               (orig-desc (cdr key-binding))
+               (group (which-key--group-p orig-desc))
+               (keys (which-key--current-key-string key))
+               (local (eq (which-key--safe-lookup-key local-map (kbd keys))
+                          (intern orig-desc)))
+               (hl-face (which-key--highlight-face orig-desc))
+               (key-binding (which-key--maybe-replace (cons keys orig-desc))))
+          (when (consp key-binding)
+            (list (which-key--propertize-key
+                   (car (last (split-string (car key-binding) " "))))
+                  sep-w-face
+                  (which-key--propertize-description
+                   (cdr key-binding) group local hl-face orig-desc)))))
+      unformatted))))
 
 (defun which-key--get-keymap-bindings (keymap &optional filter)
   "Retrieve top-level bindings from KEYMAP."